package com.xk857.modules.controller;


import com.xk857.modules.entities.Student;
import com.xk857.modules.entities.req.FindStudentReq;
import com.xk857.modules.entities.req.StudentReq;
import com.xk857.modules.entities.vo.StudentSimpleVo;
import com.xk857.modules.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author CV大魔王
 * @since 2021-09-05
 */
@Api(tags = "招新相关")
@RestController
@RequestMapping("/api/v1/student")
public class StudentController {

    @Autowired
    private IStudentService studentService;

    @ApiOperation("测试")
    @GetMapping("/test")
    public boolean test(){
        return true;
    }

    @ApiOperation("新生填报")
    @PostMapping("/add")
    public Student add(@RequestBody @Validated StudentReq studentReq){
        return studentService.add(studentReq);
    }

    @ApiOperation("新生列表")
    @GetMapping("/list")
    public List<StudentSimpleVo> list(){
        return studentService.listStudentSimple();
    }

    @ApiOperation("新生列表-管理员")
    @PostMapping("/list/all")
    public List<Student> findAll(@RequestBody @Validated FindStudentReq req){
        return studentService.listAll(req);
    }

    @ApiOperation("查询所有班级")
    @GetMapping("/classes")
    public List<String> findAllClasses(){
        return studentService.findAllClasses();
    }

    @ApiOperation("总共有多少个学生")
    @GetMapping("/count")
    public Integer count(){
        return studentService.count();
    }
}
